/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.node.MenuNode;
import cn.stylefeng.guns.base.shiro.ShiroUser;
import cn.stylefeng.guns.sys.core.exception.InvalidKaptchaException;
import cn.stylefeng.guns.sys.core.log.LogManager;
import cn.stylefeng.guns.sys.core.log.factory.LogTaskFactory;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import cn.stylefeng.guns.sys.core.util.KaptchaUtil;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.model.MenuDto;
import cn.stylefeng.guns.sys.modular.system.service.MenuService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.code.kaptcha.Constants;
import com.openapi.sdk.service.DataExchangeService;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.stylefeng.roses.core.util.HttpContext.getIp;

/**
 * 登录控制器
 *
 * @author fengshuonan
 * @Date 2017年1月10日 下午8:25:24
 */
@Controller
public class LoginController extends BaseController {


    @Autowired
    private UserService userService;
    @Autowired
    private  MenuService menuService;


    // 主账号 中交
    //车辆轨迹查询
    public static String transTimeManage(){

            Map <String, String> map = new HashMap <String, String>(3);
            map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
            map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
            map.put("type", "trackView");
            String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:" + url);
            // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:" + res);
            JSONObject resultJson = JSONObject.parseObject(res);
            //通过key-value的形式获取值
            String resultCode = (String) resultJson.get("result");
            //System.out.println(resultCode);
        return resultCode;
    }
    //全图监控地址
    public static String transTimeManage1(){
            Map<String, String> map = new HashMap<String, String>(3);
            map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
            map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
            map.put("type", "mapOverView");
            String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
            // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
            JSONObject resultJson = JSONObject.parseObject(res);
            //通过key-value的形式获取值
            String resultCode = (String) resultJson.get("result");
            //System.out.println(resultCode);

        return resultCode;
    }
    //在途管理
    public static String transTimeManage2(){

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "transList");
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //消息管理
    public static String transTimeManage3(){

            Map<String, String> map = new HashMap<String, String>(3);
            map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
            map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
            map.put("type", "transportWarnMsg");
            String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
            // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
            JSONObject resultJson = JSONObject.parseObject(res);
            //通过key-value的形式获取值
            String resultCode = (String) resultJson.get("result");
            //System.out.println(resultCode);
        return resultCode;
    }
    //运输行程
    public static String transTimeManage4(){
            Map<String, String> map = new HashMap<String, String>(3);
            map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
            map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
            map.put("type", "pathTrack");
            String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
            // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
            JSONObject resultJson = JSONObject.parseObject(res);
            //通过key-value的形式获取值
            String resultCode = (String) resultJson.get("result");
            //System.out.println(resultCode);
        return resultCode;
    }

    // 子账号 恒安
    //车辆轨迹查询
    public  String HengAn() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13345236936");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);
        Map <String, String> map = new HashMap <String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "trackView");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:" + url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:" + res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //全图监控地址
    public  String HengAn1() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13345236936");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "mapOverView");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);

        return resultCode;
    }
    //在途管理
    public  String HengAn2() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13345236936");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "transList");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //消息管理
    public  String HengAn3() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13345236936");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "transportWarnMsg");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //运输行程
    public  String HengAn4() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13345236936");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "pathTrack");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }


    // 子账号 孝感
    //车辆轨迹查询
    public  String Xiaogan() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13256430602");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);
        Map <String, String> map = new HashMap <String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "trackView");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:" + url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:" + res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //全图监控地址
    public  String Xiaogan1() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13256430602");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "mapOverView");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);

        return resultCode;
    }
    //在途管理
    public  String Xiaogan2() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13256430602");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "transList");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //消息管理
    public  String Xiaogan3() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13256430602");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "transportWarnMsg");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }
    //运输行程
    public  String Xiaogan4() throws JsonProcessingException {
        User user = userService.getcurrentUser();
        Map<String, Object> pluginParams = new HashMap<>();
        pluginParams.put("pUserPhoneNo", "13256430602");
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(pluginParams);

        Map<String, String> map = new HashMap<String, String>(3);
        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
        map.put("type", "pathTrack");
        map.put("pluginParams", json);
        String url = " https://zhiyunopenapi.95155.com/save/apis/pluginUrl";
        DataExchangeService des = null;
        try {
            des = new DataExchangeService(5000, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("请求地址:"+url);
        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
        String res = null;
        try {
            res = des.postHttps(url, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //System.out.println("返回:"+ res);
        JSONObject resultJson = JSONObject.parseObject(res);
        //通过key-value的形式获取值
        String resultCode = (String) resultJson.get("result");
        //System.out.println(resultCode);
        return resultCode;
    }


// 创建子账号
//    public static String transTimeManage5(){
//        Map<String, String> map = new HashMap<String, String>(3);
//        map.put("cid", "96c66565-162a-436a-b3ef-8db0da2c0222");
//        map.put("srt", "d42d62c9-130a-43fe-8ce3-f407c64208fa");//私钥用于SDK生成签名，不会在请求中传输
//        map.put("phoneNum", "13256430602");
//        map.put("password", "lww123456");
//        String url = " https://zhiyunopenapi.95155.com/save/apis/subUserSaveLingDong";
//        DataExchangeService des = null;
//        try {
//            des = new DataExchangeService(5000, 8000);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println("请求地址:"+url);
//        // 通过https方式调用，此方法内部会使用私钥生成签名参数sign,私钥不会发送
//        String res = null;
//        try {
//            res = des.postHttps(url, map);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println("返回:"+ res);
//        JSONObject resultJson = JSONObject.parseObject(res);
//        //通过key-value的形式获取值
//        String resultCode = (String) resultJson.get("result");
//        System.out.println(resultCode);
//        return resultCode;
//    }


    /**
     * 跳转到主页
     *
     * @author fengshuonan
     * @Date 2018/12/23 5:41 PM
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) throws JsonProcessingException {

        //获取当前用户角色列表
        ShiroUser user = ShiroKit.getUserNotNull();
        List<Long> roleList = user.getRoleList();

        String userAgent = super.getHttpServletRequest().getHeader("user-agent");

        if (roleList == null || roleList.size() == 0) {
            ShiroKit.getSubject().logout();
            model.addAttribute("tips", "该用户没有角色，无法登陆");
            return "/login.html";
        }else {
            for (Long role: roleList) {
                if (role.equals(1731559716201852929L)) {

                    // 主账号
                    //车辆轨迹查询
                    String s = this.transTimeManage();
                    MenuDto menu = new MenuDto();
                    menu.setName("车辆轨迹查询");
                    menu.setUrl(s);
                    menu.setPcode("dashboard");
                    menuService.updateURl(menu);
                    String s1 = this.transTimeManage1();
                    //全图监控地址
                    MenuDto menu1 = new MenuDto();
                    menu1.setName("全图监控");
                    menu1.setUrl(s1);
                    menu1.setPcode("dashboard");
                    menuService.updateURl(menu1);
                    //在途管理
                    String s2 = this.transTimeManage2();
                    MenuDto menu2 = new MenuDto();
                    menu2.setName("在途管理");
                    menu2.setUrl(s2);
                    menu2.setPcode("dashboard");
                    menuService.updateURl(menu2);
                    //消息管理
                    String s3 = this.transTimeManage3();
                    MenuDto menu3 = new MenuDto();
                    menu3.setName("消息管理");
                    menu3.setUrl(s3);
                    menu3.setPcode("dashboard");
                    menuService.updateURl(menu3);
                    //车辆轨迹地址
                    String s4 = this.transTimeManage4();
                    //System.out.println(s4);
                    //System.out.println(s4);
                    //System.out.println(s4);
                    //System.out.println(s4);
                    //System.out.println(s4);
                    MenuDto menu4 = new MenuDto();
                    menu4.setName("运输行程");
                    menu4.setUrl(s4);
                    menu4.setPcode("dashboard");
                    menuService.updateURl(menu4);

           }

                if (role.equals(1770988745677762562L)) {
                  // 子账号 恒安
                    //车辆轨迹查询
                    String url = this.HengAn();
                    MenuDto h1 = new MenuDto();
                    h1.setName("车辆轨迹查询");
                    h1.setUrl(url);
                    h1.setPcode("positioning");
                    menuService.updateURl(h1);
                    String url1 = this.HengAn1();
                    //全图监控地址
                    MenuDto h2=new MenuDto();
                    h2.setName("全图监控");
                    h2.setUrl(url1);
                    h2.setPcode("positioning");
                    menuService.updateURl(h2);
                    //在途管理
                    String url2 = this.HengAn2();
                    MenuDto h3=new MenuDto();
                    h3.setName("在途管理");
                    h3.setUrl(url2);
                    h3.setPcode("positioning");
                    menuService.updateURl(h3);
                    //消息管理
                    String url3 = this.HengAn3();
                    MenuDto h4=new MenuDto();
                    h4.setName("消息管理");
                    h4.setUrl(url3);
                    h4.setPcode("positioning");
                    menuService.updateURl(h4);
                    //车辆轨迹地址
                    String url4 = this.HengAn4();
                    MenuDto h5=new MenuDto();
                    h5.setName("运输行程");
                    h5.setUrl(url4);
                    h5.setPcode("positioning");
                    menuService.updateURl(h5);

                }
               if (role.equals(1770990320932515842L)) {
                    // 子账号 孝感
                    //车辆轨迹查询
                    String url5 = this.Xiaogan();
                    MenuDto h6 = new MenuDto();
                    h6.setName("车辆轨迹查询");
                    h6.setUrl(url5);
                    h6.setPcode("query");
                    menuService.updateURl(h6);
                    String url6 = this.Xiaogan1();
                    //全图监控地址
                    MenuDto h7=new MenuDto();
                    h7.setName("全图监控");
                    h7.setUrl(url6);
                    h7.setPcode("query");
                    menuService.updateURl(h7);
                    //在途管理
                    String url8 = this.Xiaogan2();
                    MenuDto h8=new MenuDto();
                    h8.setName("在途管理");
                    h8.setUrl(url8);
                    h8.setPcode("query");
                    menuService.updateURl(h8);
                    //消息管理
                    String url9 = this.Xiaogan3();
                    MenuDto h9=new MenuDto();
                    h9.setName("消息管理");
                    h9.setUrl(url9);
                    h9.setPcode("query");
                    menuService.updateURl(h9);
                    //车辆轨迹地址
                    String url10 = this.Xiaogan4();
                    MenuDto h10=new MenuDto();
                    h10.setName("运输行程");
                    h10.setUrl(url10);
                    h10.setPcode("query");
                    menuService.updateURl(h10);
               }
            }

            List<MenuNode> menus = userService.getUserMenuNodes(roleList);
            model.addAttribute("menus", menus);
            return "/index.html";
        }

    }

    /**
     * 跳转到登录页面
     *
     * @author fengshuonan
     * @Date 2018/12/23 5:41 PM
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {

        String userAgent = super.getHttpServletRequest().getHeader("user-agent");
        if (ShiroKit.isAuthenticated() || ShiroKit.getUser() != null) {
            return REDIRECT + "/";
        } else {
            return "/login2023.html";
        }

    }

    @RequestMapping(value = "/aotuPrintHxFcd", method = RequestMethod.GET)
    public String aotuPrintHxFcd() {
        return "/aotuPrintHxFcd.html";
    }

    /**
     * 点击登录执行的动作
     *
     * @author fengshuonan
     * @Date 2018/12/23 5:42 PM
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String loginVali(String username,String password) {
        //Object a=ShiroKit.getSession().getAttribute("sessionFlag");

//    	String username = super.getPara("username").trim();
//        String password = super.getPara("password").trim();
//        String remember = super.getPara("remember");

        //验证验证码是否正确
        if (KaptchaUtil.getKaptchaOnOff()) {
            String kaptcha = super.getPara("kaptcha").trim();
            String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
            if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
                throw new InvalidKaptchaException();
            }
        }

        Subject currentUser = ShiroKit.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());

        //如果开启了记住我功能
        token.setRememberMe(true);
//        if ("on".equals(remember)) {
//        } else {
//            token.setRememberMe(false);
//        }

        //执行shiro登录操作
        currentUser.login(token);
        //登录成功，记录登录日志
        ShiroUser shiroUser = ShiroKit.getUserNotNull();
        LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), getIp()));
        //更新最后登录时间
        User updateUser = new User();
        updateUser.setUserId(shiroUser.getId());
        updateUser.setLastLoginTime(new Date());
        userService.updateLastLoginTimeById(updateUser);
        //Session session = ShiroKit.getSession();
        // session.removeAttribute();
        //ShiroKit.getSession().getAttributeKeys();
        ShiroKit.getSession().setAttribute("sessionFlag", username);
        //Object b=ShiroKit.getSession().getAttribute("sessionFlag");
        // sessionId = ShiroKit.getSession().getId();
        return REDIRECT + "/";
    }


    /**
     * 退出登录
     *
     * @author fengshuonan
     * @Date 2018/12/23 5:42 PM
     */
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logOut() {
        LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUserNotNull().getId(), getIp()));
        ShiroKit.getSubject().logout();
        deleteAllCookie();
        String userAgent = super.getHttpServletRequest().getHeader("user-agent");
        return REDIRECT + "/login";

    }
}
